package com.formssi.service.Impl;

import com.formssi.mapper.ExcelMapper;
import com.formssi.pojo.User2;
import com.formssi.pojo.UserExcel;
import com.formssi.pojo.UserExcel2;
import com.formssi.service.ExcelService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ExcelServiceImpl implements ExcelService {

    @Resource
    private ExcelMapper excelMapper;

    //查询用户列表
    @Override
    public List<UserExcel> findAll() {
        return excelMapper.list();
    }

    //保存用户列表
    @Override
//    @Transactional(propagation = Propagation.SUPPORTS)
    public void saveAll(List<UserExcel> users) {
        for (UserExcel user : users) {
            user.setId(null);
            System.out.println(user);
            excelMapper.save(user);
        }
    }

    //easyExcel下保存用户信息
    @Override
    public void saveAll2(List<UserExcel2> users) {
        for (UserExcel2 user : users) {
            user.setId(null);
            System.out.println(user);
            excelMapper.save2(user);
        }
    }

}
